#!/bin/bash

# 学习计划平台 - 宝塔部署脚本
# 使用方法：./deploy-to-baota.sh

echo "🚀 开始部署学习计划平台到宝塔..."

# 检查是否为Git仓库
if [ ! -d ".git" ]; then
    echo "❌ 错误：当前目录不是Git仓库"
    exit 1
fi

# 检查是否有未提交的更改
if [ -n "$(git status --porcelain)" ]; then
    echo "📝 检测到未提交的更改，正在提交..."
    git add .
    echo "请输入提交信息："
    read commit_message
    if [ -z "$commit_message" ]; then
        commit_message="更新功能页面：学习进度、打卡、资源管理"
    fi
    git commit -m "$commit_message"
fi

# 推送到远程仓库
echo "📤 推送代码到Gitee..."
git push origin main

if [ $? -eq 0 ]; then
    echo "✅ 代码推送成功！"
else
    echo "❌ 代码推送失败，请检查网络连接"
    exit 1
fi

echo ""
echo "🎉 部署完成！接下来请在宝塔面板执行以下操作："
echo ""
echo "1. 📁 进入网站目录："
echo "   cd /www/wwwroot/你的域名"
echo ""
echo "2. 🔄 拉取最新代码："
echo "   git pull origin main"
echo ""
echo "3. 📦 安装/更新前端依赖："
echo "   cd client"
echo "   npm install"
echo "   npm run build"
echo ""
echo "4. 🔧 重启应用："
echo "   pm2 restart study-plan"
echo ""
echo "5. ✅ 检查应用状态："
echo "   pm2 status"
echo "   pm2 logs study-plan"
echo ""
echo "🌐 部署完成后，请访问你的网站查看新功能："
echo "   • 学习进度页面：完整的54天学习计划跟踪"
echo "   • 每日打卡页面：打卡记录、统计和日历"
echo "   • 学习资源页面：资源分类、搜索和收藏"
echo ""
echo "📚 新功能特点："
echo "   ✨ 详细的学习进度跟踪"
echo "   ✨ 每日打卡记录和统计"
echo "   ✨ 丰富的学习资源库"
echo "   ✨ 响应式设计，支持移动端"
echo "   ✨ 本地数据持久化"
echo "" 